<?php
/* SVN FILE: $Id: coaches_controller.php 250 2010-06-17 10:55:41Z gregory.rome $ */
/**
 * Coaches Controller.
 *
 * Addition, deletion and edition are administrators tasks.
 *
 * cBBweb : Digital Blood Bowl league interface (http://code.google.com/p/cbbweb/)
 * Copyright 2009-2010, Grégory Romé.
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright     Copyright 2009-2010, Grégory Romé.
 * @link          http://code.google.com/p/cbbweb/ cBBweb Project
 * @package       cbbweb
 * @subpackage    cbbweb.controllers
 * @version       $Revision: 250 $
 * @modifiedby    $LastChangedBy: gregory.rome $
 * @lastmodified  $Date: 2010-06-17 10:55:41 +0000 (Thu, 17 Jun 2010) $
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */

/**
 * Coaches Controller.
 *
 * @package       cbbweb
 * @subpackage    cbbweb.controllers
 */
class CoachesController extends AppController {

	var $name = 'Coaches';

	function index() {
		$this->Coach->recursive = 1;
        $coaches = $this->paginate();
        if (isset($this->params['requested'])) {
            return $coaches;
        } else {
        $this->set('coaches', $coaches);
        }
	}

    function view($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid Race.', true));
            $this->redirect(array('action'=>'index'));
        }

		$this->Coach->recursive = 1;
        $coach = $this->Coach->read(null,$id);
        $this->set('coach', $coach);
    }

	function add() {
		if (!empty($this->data)) {
			$this->Coach->create();
			$this->data['Coach']['strTag_Voice'] = "";
			$this->data['Coach']['strTag_Head'] = "";

			if ($this->Coach->save($this->data)) {

				$this->Session->setFlash(__('The Coach has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Coach could not be saved. Please, try again.', true));
			}
		}
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Coach', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->Coach->save($this->data)) {
				$this->Session->setFlash(__('The Coach has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Coach could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Coach->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Coach', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Coach->del($id)) {
			$this->Session->setFlash(__('Coach deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}

}
?>
